# -*- coding: utf-8 -*-
"""
author:码同学 极光
date:2023-02-04
desc: 
sample: 
"""
import os
import random

import pytest
import requests

from util import getcsv_listdict, get_project_path


class TestLogin:
    host = 'http://82.156.74.26:9088' #静态 类变量
   #一次
    def setup_class(self):
        url = self.host + "/pinter/bank/api/login2"
        data = {
            'userName': 'admin',
            'password': '1234',
        }
        response = requests.post(url, data=data)
        print(f"是否成功{response.status_code}")
        print(f"返回结果{response.text}")
        # 提取处理
        json = response.json()
        token = json["data"]
        self.token = token


    #方法调用一次执行
    def setup_method(self):
        phoneNumber = ["130", "131", "138", "145", "146", "147", "150", "151", "152", "172", "174", "175", "180", "181",
                       "182", "198"]
        phone = random.choice(phoneNumber) + str(random.randint(10000000, 99999999))
        self.testphone = phone


    @pytest.mark.parametrize("param", getcsv_listdict(os.path.join(get_project_path(), "files", "user.csv")))
    def testbuy(self, param):
        data = {
            'userName': param.get('username'),
            'phone': self.testphone
        }
        url = self.host + "/pinter/bank/api/query2"
        headers = {
            # 开发提供
            'testfan-token': self.token
        }
        response = requests.get(url, params=data, headers=headers)
        print(f"是否成功{response.status_code}")
        print(f"返回结果{response.text}")


    def testback(self):
        print(self.token)
        # url = host + "/pinter/bank/api/query2"
        # headers = {
        #     # 开发提供
        #     'testfan-token': token
        # }
        # response = requests.get(url, params=data, headers=headers)
        # print(f"是否成功{response.status_code}")
        # print(f"返回结果{response.text}")

